<?php
/**
 * Created by PhpStorm.
 * User: dx
 * Date: 17/02/27
 * Time: 上午11:30
 */
class ShopTimePart extends Eloquent
{
    protected $table = "shop_time_part";

    public static function selectShopTime($data,$shop_id){
        $sso=ShopStockOrder::where("stock_date",$data)->where("shop_id",$shop_id)->first();
        if($sso->type==1){
            $cso=DB::select("SELECT cso.*,ctp.`start`,ctp.`end` FROM `shop_stock_order` cso LEFT JOIN shop_time_part ctp on cso.time_part_id=ctp.id  where cso.shop_id=? and cso.stock_date=? and cso.stock_all>cso.stock_current order by ctp.`start` ",array($shop_id,$data));
        }else{
            $cso=DB::select("SELECT cso.*,tpl.`start`,tpl.`end` FROM `shop_stock_order` cso LEFT JOIN time_part_template tpl on cso.time_part_id=tpl.id  where cso.shop_id=? and cso.stock_date=? and cso.stock_all>cso.stock_current order by tpl.`start`",array($shop_id,$data));
        }
        if($data==date("Y-m-d",time())){
            $array=array();
            $time=date("Y-m-d H:i:s",time());
            foreach ($cso as $_cso) {
                $date=$_cso->stock_date." ".$_cso->start;
                if($date>=$time){
                    $array[]=(array)$_cso;
                }
            }
            return $array;
        }else{
            $a=array();
            foreach($cso as $_c){
                $a[] = (array)$_c;
            }
            return $a;
        }
    }


}
